<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('任务中心列表')" />
    <style>
        /*显示不全用...表示*/
        .ellipsis {
            width: 100px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: inline-block;
        }
        .ellipsis-summary{
            width: 150px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: inline-block;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <!--<li>
                                <label>用户id </label>
                                <input type="text" name="userId"/>
                            </li>-->
                            <li>
                                <label>任务标题：</label>
                                <input type="text" name="taskTitle"/>
                            </li>
                            </li>
                            <li>
                                <label>任务标签：</label>
                                <input type="text" name="tag" />
                            </li>
                            <li>
                                <label>结束时间： </label>
                                <input type="text" class="time-input"  name="finishDate"/>
                            </li>
                            <li>
                            任务状态：<select name="status" th:with="type=${@dict.getType('task_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="taskcenter:taskcenter:add">
                    <i class="fa fa-plus"></i> 发布任务
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="taskcenter:taskcenter:edit">
                    <i class="fa fa-edit"></i> 修改任务
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="taskcenter:taskcenter:remove">
                    <i class="fa fa-remove"></i> 删除任务
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="taskcenter:taskcenter:export">
                    <i class="fa fa-download"></i> 导出任务
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"
                       data-show-custom-view="true" data-custom-view="customViewFormatter"
                       data-show-custom-view-button="true">
                </table>
            </div>
        </div>
    </div>

     <template id="profileTemplate">
         <div class="col-sm-4">
             <div class="contact-box">
                 <a href="javascript:void(0)" shiro:hasPermission="taskcenter:taskcenter:detail" onclick="goTaskDetail('%id%','%taskTitle1%')">
                     <div class="col-sm-4">
                         <div class="text-center">
                             <img alt="image" class="img-circle m-t-xs img-responsive" src="%taskThumbnail%" style="max-width: 80px;max-height: 110px">
                             <!--<div class="m-t-xs font-bold">%userName%</div>-->
                         </div>
                     </div>
                     <div class="col-sm-8">
                         <h3><strong class="ellipsis">%taskTitle%</strong></h3>
                         <p>%status%</p>
                         <address>
                             <strong>%finishDate%</strong><br>
                             <span class="ellipsis-summary">%taskSummary%</span><br>
                             <!--<abbr title="Phone">Tel:</abbr> %userPhone%-->
                         </address>
                     </div>
                     <div class="clearfix"></div>
                 </a>
             </div>
         </div>
     </template>

     <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-custom-view-js" />
     <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('taskcenter:taskcenter:edit')}]];
        var removeFlag = [[${@permission.hasPermi('taskcenter:taskcenter:remove')}]];
        var detailFlag = [[${@permission.hasPermi('taskcenter:taskcenter:detail')}]];
        var prefix = ctx + "taskcenter/taskcenter";
        var datas = [[${@dict.getType('task_status')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                detailUrl: prefix + "/detail/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "任务中心",
                customViewFormatter:customViewFormatter,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '任务ID'
                },
                {
                    field: 'taskTitle',
                    title: '任务标题'
                },
                {
                    field: 'tag',
                    title: '任务标签'
                },
                {
                    field: 'finishDate',
                    title: '结束时间'
                },
                {
                    field: 'status',
                    title: '任务状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + detailFlag + "' href='javascript:void(0)' onclick='$.operate.detail(" + row.id + ")'><i class='fa fa-search'></i>任务详情</a> ");
                        actions.push('<a class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function customViewFormatter (data) {
            var template = $('#profileTemplate').html()
            var view = ''
            $.each(data, function (i, row) {
                view += template.replace('%taskTitle%', row.taskTitle)
                    .replace('%status%', $.table.selectDictLabel(datas, row.status))
                    .replace('%taskThumbnail%', row.taskThumbnail)
                    .replace('%finishDate%', row.finishDate)
                    .replace('%taskSummary%',row.taskSummary)
                    .replace('%id%',row.id)
                    .replace('%taskTitle1%',row.taskTitle);
            })

            return `<div class="row mx-0">${view}</div>`
        }

        /* 任务详情*/
        function goTaskDetail(taskId,taskTitle) {
            var url = ctx + 'taskcenter/taskcenter/detail';
            if ($.common.isNotEmpty(taskId)) {
                url += '/' + taskId;
            }
            $.modal.openTab(taskTitle, url);
        }
    </script>
</body>
</html>